package com.beidouin.GnssMain.sample;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.CoordinateConverter;
import com.beidouin.GnssMain.FileManager;
import com.beidouin.GnssMain.R;
import com.beidouin.GnssMain.models.PilotInfo;

public class LxActivity extends AppCompatActivity {
    MapView map;
    private BaiduMap mBaiduMap;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lxactivity);
        map= (MapView) findViewById(R.id.map);
        mBaiduMap=map.getMap();

        MapStatus.Builder builder = new MapStatus.Builder();
        LatLng center = new LatLng(39.915071, 116.403907); // 默认 天安门
        float zoom = 11.0f; // 默认 11级
        Intent intent = getIntent();
//        mEnableCustomStyle = intent.getBooleanExtra("customStyle", true);
        center = new LatLng(intent.getDoubleExtra("y", 39.915071),
                intent.getDoubleExtra("x", 116.403907));
        zoom = intent.getFloatExtra("level", 11.0f);
        builder.target(center).zoom(zoom);
        MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build());

        mBaiduMap.setMapStatus(mapStatusUpdate);
       // validateUI();
    }


    private void validateUI() {

        double x;
        double y;
        x= PilotInfo.getInstance().getLongitude_double();
        y=PilotInfo.getInstance().getLatitude_double();
        Log.i("x","==================="+x);
        LatLng point = new LatLng(y,x);
        CoordinateConverter converter  = new CoordinateConverter();
        converter.from(CoordinateConverter.CoordType.GPS);
        // sourceLatLng待转换坐标
        converter.coord(point);
        LatLng desLatLng = converter.convert();
        point=desLatLng;
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.drawable.map_sign);
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        mBaiduMap.addOverlay(option);
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(point));
        if(FileManager.getInstance().get_FileStreamSta()==FileManager.ISPLAYING) {
            double x2;
            double y2;
            x2 = PilotInfo.getInstance().getLongitude_FromPC_double();
            y2 = PilotInfo.getInstance().getLatitude_FromPC_double();
            LatLng point2 = new LatLng(y2, x2);
            CoordinateConverter converter2 = new CoordinateConverter();
            converter2.from(CoordinateConverter.CoordType.GPS);
            // sourceLatLng待转换坐标
            converter2.coord(point2);
            LatLng desLatLng2 = converter2.convert();
            point2 = desLatLng2;
            BitmapDescriptor bitmap2 = BitmapDescriptorFactory
                    .fromResource(R.drawable.map_sign);
            OverlayOptions option2 = new MarkerOptions()
                    .position(point2)
                    .icon(bitmap2);
            mBaiduMap.addOverlay(option2);
            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(point2));
        }
    }
}
